/*
 * @Author: your name
 * @Date: 2021-12-09 19:04:03
 * @LastEditTime: 2021-12-10 20:03:51
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \12.9作业\demo\index.ts
 */
var EventEmitter = /** @class */ (function () {
    function EventEmitter() {
        // your code 定义私有属性 events
        this.preson = {};
    }
    EventEmitter.prototype.on = function (eventName, listener) {
        // your code
        if (!this.preson[eventName]) {
            this.preson[eventName] = [listener];
        }
        else {
            this.preson[eventName].push(listener);
        }
    };
    EventEmitter.prototype.emit = function (eventName) {
        var args = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            args[_i - 1] = arguments[_i];
        }
        // your code
        //   console.log(eventName);
        this.preson[eventName] && this.preson[eventName].map(function (event) { return event.apply(void 0, args); });
        //   console.log(this.preson);
    };
    EventEmitter.prototype.off = function (eventName, listener) {
        // your code
    };
    EventEmitter.prototype.once = function (eventName, listener) {
        // your code
    };
    return EventEmitter;
}());
// 调用示例
var req = new EventEmitter();
var handler = function () {
    console.log('我的');
};
req.on('data', handler);
req.once('data', handler);
// req.off('data', handler)
req.emit('data');
req.emit('data');
